//
//  MTHomeToolBar.swift
//  MTWeiBo
//
//  Created by user on 2017/7/27.
//  Copyright © 2017年 itcast. All rights reserved.
//

import UIKit
import SnapKit


class MTHomeToolBar: UIView {
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    //搭建界面
    private func setupUI() {
        //backgroundColor = UIColor.orange
        //实例化控件
        let retweetButton = addChildButten(imageName: "timeline_icon_retweet", title: "转发")
        let commnetButton = addChildButten(imageName: "timeline_icon_comment", title: "评论")
        let unlikeButton = addChildButten(imageName: "timeline_icon_unlike", title: "赞")
        //约束
        retweetButton.snp.makeConstraints { (make) in
            make.top.leading.bottom.equalTo(self)
            make.width.equalTo(commnetButton)
        }
        commnetButton.snp.makeConstraints { (make) in
            make.top.bottom.equalTo(self)
            make.leading.equalTo(retweetButton.snp.trailing)
            make.width.equalTo(unlikeButton)
        }
        unlikeButton.snp.makeConstraints { (make) in
            make.top.bottom.trailing.equalTo(self)
            //关键约束
            make.leading.equalTo(commnetButton.snp.trailing)
        }
        
        //  第一条条线
        let firstLineView = addLineView()
        //  第二条条线
        let secondLineView = addLineView()
        
        //  添加约束
        firstLineView.snp.makeConstraints { (make) in
            make.centerX.equalTo(retweetButton.snp.trailing)
            make.centerY.equalTo(retweetButton)
        }
        secondLineView.snp.makeConstraints { (make) in
            make.centerX.equalTo(commnetButton.snp.trailing)
            make.centerY.equalTo(commnetButton)
        }

    }
    
    // 添加子按钮
    private func addChildButten(imageName: String,title: String) -> UIButton {
        let butten = UIButton()
        //设置属性
        butten.setImage(UIImage(named:imageName ), for: .normal)
        butten.setBackgroundImage(UIImage(named: "timeline_card_bottom_background"), for: .normal)
        butten.setTitle(title, for: .normal)
        butten.titleLabel?.font = UIFont.systemFont(ofSize: 14)
        butten.setTitleColor(UIColor.darkGray, for: .normal)
        //取消高亮
        butten.adjustsImageWhenHighlighted = false
        //添加
        addSubview(butten)
        return butten
    }
    
    //添加竖线视图
    private func addLineView() -> UIImageView {
        let imageView = UIImageView(image: UIImage(named: "timeline_card_bottom_line"))
        
        addSubview(imageView)
        return imageView
    }
    
}
